package moltencore.game.collision;

public class LineSegment /*implements ICollidable*/ {
	/*private static final int COLLISION_ACCURACY = 5;
	private Vector2 start;
	private Vector2 end;
	private Vector2 line;
	private float lineDotProduct;

	public LineSegment(Vector2 start, Vector2 end) {
		this.start = start;
		this.end = end;
		line = Vector2.substract(end, start);
		lineDotProduct = Vector2.dot(line, line);
	}

	@Override
	public Vector2 collisionPoint(Bubble bubble, Vector2 movement) {
		if(!collidesCircle(Vector2.add(bubble.getPosition(), movement), Bubble.COLLISION_RADIUS)) {
			return null;
		}
		Vector2 movementModifier = new Vector2(movement);
		for(int i = 0; i < COLLISION_ACCURACY; i++) {
			movementModifier.multiply(0.5f);
			do {
				movement.substract(movementModifier);
			} while(collidesCircle(Vector2.add(bubble.getPosition(), movement), Bubble.COLLISION_RADIUS));
			movementModifier.multiply(0.5f);
			do {
				movement.add(movementModifier);
			} while(!collidesCircle(Vector2.add(bubble.getPosition(), movement), Bubble.COLLISION_RADIUS));
		}
		return movement;
	}

	private boolean collidesCircle(Vector2 circlePosition, float radius) {
		Vector2 startToBubble = Vector2.substract(circlePosition, start);
		float startToBubble_line_dot = Vector2.dot(startToBubble, line);
		float t = startToBubble_line_dot / lineDotProduct;

		if(t < 0.0f) {
			t = 0.0f;
		}
		else if(t > 1.0f) {
			t = 1.0f;
		}

		Vector2 collisionPointOnLine = Vector2.add(start, Vector2.multiply(line, t));

		Vector2 h = Vector2.substract(collisionPointOnLine, circlePosition);
		float h_dot = Vector2.dot(h, h);
		float rPow2 = radius * radius;

		return (h_dot > rPow2);
	}*/
}
